<template>
  <div id="shop-item" >
    <div class="item-selector">
      <CheckButton @checkBtnClick="checkedChange" v-model="itemInfo.checked"></CheckButton>
    </div>
    <div class="item-img">
      <img :src="itemInfo.imgURL" alt="商品图片">
    </div>
    <div class="item-info">
      <div class="item-title" name="aaa">{{itemInfo.title}}</div>
      <div class="item-desc">商品描述: {{itemInfo.explain}}</div> 
    

      <div class="info-bottom"> 
        <div class="item-price left">{{itemInfo.price}}</div>
         <span class="sleft"  @click="addLeft">+</span>
         <span class="sright" @click="minus">-</span>
        <div class="item-count right" >x{{itemInfo.count}}</div>
      </div>
    
    </div>
  </div> 
</template> 

<script>
  import CheckButton from './CheckButton'

  export default {
    name: "ShopCartItem",
    props: {
      itemInfo: Object,
      index:Number
    },
    components: {
      CheckButton
    },
  
    methods: { 
        minus(){  
           if(this.itemInfo.count!==1){
              this.itemInfo.count--;
        }else{
           this.$emit('minus',this.index)
        }
      },   
     addLeft( ) { 
       this.itemInfo.count++;
      },
  
      checkedChange: function () {
        this.itemInfo.checked = !this.itemInfo.checked;
        
      }
    }
  }
</script>

<style scoped>
 
  .info-bottom {
    margin-top: 10px;
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
     
    
  }
.sleft{ 
    display: inline-block;
    width: 32px;
    height: 19px;
    background: #00000099;
    line-height: 19px;
    font-size: 26px;
    text-align: center;
    color: white;
    border: 1px solid white;
    margin-left: 25px;;
}
.sright{
    display: inline-block;
    width: 32px;
    height: 19px;
    background: #00000099;
    line-height: 19px;
    font-size: 26px;
    text-align: center;
    color: white;
    border: 1px solid white;
    margin-left: 25px;;
}
  #shop-item {
    width: 100%;
    display: flex;
    font-size: 0;
    padding: 5px;
    border-bottom: 1px solid #ccc;
  }

  .item-selector {
    width: 14%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .item-title, .item-desc {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .item-img {
    padding: 5px;
    /*border: 1px solid #ccc;*/
  }

  .item-img img {
    width: 80px;
    height: 100px;
    display: block;
    border-radius: 5px;
  }

  .item-info {
    font-size: 17px;
    color: #333;
    padding: 5px 10px;
    position: relative;
    overflow: hidden;
  }

  .item-info .item-desc {
    font-size: 14px;
    color: #666;
    margin-top: 15px;
  }



  .info-bottom .item-price {
    color: orangered;
  }
</style>
